package net.towee.model.impl;

import net.towee.model.ProfileArea;

import com.google.code.morphia.annotations.Embedded;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;

/**
 * Area of extended profile
 * @author c58
 */
@Embedded
public class ProfileAreaImpl implements ProfileArea {

	private String name;
	private String value; 
	
	public ProfileAreaImpl(){}
	public ProfileAreaImpl(String name, String value){
		this(name, value, true);
	}
	
	public ProfileAreaImpl(String name, String value, boolean escape){
		if(escape) {
			setName(name);
			setValue(value);
		}	else {
			this.name = name;
			this.value = value;
		}
	}
	
	@Override
	public String getValue() {
		return value;
	}

	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setValue(String value) {
		this.value = SafeHtmlUtils.htmlEscape(value);
	}

	@Override
	public void setName(String value) {
		this.name = SafeHtmlUtils.htmlEscape(value);
	}

	@Override
	public boolean equals(Object o) {
		if(o == this)
			return true;
		if(o instanceof ProfileArea && ((ProfileArea)o).getName().equals(getName()))
			return true;
			
		return false;
	}
	
	@Override
	public String toString() {
		return getName()+"<sep/>"+getValue();
	}
}